package com.gzck.gzck_verson2.pojo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * 存储解析后的报文数据
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MessageFrame {
    //中心站地址  1字节
    private String centerStationAddress;
    //遥测站ID  五字节
    private String remoteStationId;
    //通讯密码  两字节
    private String communicationPassword;
    //功能码  32定时报，33加报，34小时报  一字节
    private String functionCode;
    //报文上下行标识  一字节
    private String upOrDown;
    //报文正文长度   一字节
    private Integer messageBodyLength;
    //报文起始标识  一字节
    private String messageStart;

    //正文里面的固定长度部分为23字节
    //流水号  两字节
    private String serialNumber;
    //报文发报时间 六字节
    private String transmissionTime;
    //遥测站标识  两字节
    private String remoteStationIdentifier;
    //遥测站ID 五字节
    private String remoteStationCode;
    //遥测站类别  一字节
    private String remoteStationCategory;
    //报文时间标识  两字节
    private String observationTimeIdentifier;
    //观测时间   五字节
    private String observationTime;
    //以下不定长正文 正文长度-23
    private HashMap<String, Object> messageBody;

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("中心站地址: ").append(centerStationAddress).append("\n");
        stringBuilder.append("遥测站ID: ").append(remoteStationId).append("\n");
        stringBuilder.append("通讯密码: ").append(communicationPassword).append("\n");
        stringBuilder.append("功能码: ").append(functionCode).append("\n");
        stringBuilder.append("报文上下行标识及长度: ").append(upOrDown).append("\n");
        stringBuilder.append("正文起始符: ").append(messageStart).append("\n");
        stringBuilder.append("流水号: ").append(serialNumber).append("\n");
        stringBuilder.append("发报时间: ").append(transmissionTime).append("\n");
        stringBuilder.append("遥测站标识: ").append(remoteStationIdentifier).append("\n");
        stringBuilder.append("遥测站编码: ").append(remoteStationCode).append("\n");
        stringBuilder.append("遥测站分类码: ").append(remoteStationCategory).append("\n");
        stringBuilder.append("观测时间标识: ").append(observationTimeIdentifier).append("\n");
        stringBuilder.append("观测时间: ").append(observationTime).append("\n");

        if (messageBody != null) {
            stringBuilder.append("报文正文:\n");

            for (Map.Entry<String, Object> entry : messageBody.entrySet()) {
                stringBuilder.append("  ").append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
            }
        } else {
            stringBuilder.append("报文正文: null\n");
        }

        return stringBuilder.toString();
    }

}
